Skip to content

feat: Structured Generative Model Configuration#56

Open
carlesonielfa wants to merge 7 commits into
mainfrom
gen-model-config-refactor
Open

feat: Structured Generative Model Configuration#56
carlesonielfa wants to merge 7 commits into
mainfrom
gen-model-config-refactor

Conversation

@carlesonielfa

Copy link
Copy Markdown
Contributor

Replaces plain str model fields in agent configs with a structured LLMConfig type supporting reasoning configuration, centralized defaults, and automated model migrations — fully backwards compatible with existing stored configs.

Approach

Uses a Pydantic Annotated type with BeforeValidator to transparently coerce plain strings to `LLMConfig

Changes

Area Details
New: hyperforge/llm_config.py LLMConfig, LLMField, LLMDefaults, ReasoningConfig
New: hyperforge/db/llm_migration_utils.py walk_and_replace(), migrate_llm_models() for Alembic
14 agent configs Field type strLLMField, widget moved to LLMConfig.model_id
Manager ModelParam = str | LLMConfig, reasoning resolved and passed to ChatModel
6 agent runtime files External API calls (ChatModel, AskRequest, CreateMessageResult) use .model_id

Centralized Defaults (env-configurable)

HYPERFORGE_LLM_DEFAULT=chatgpt-azure-4o-mini # rephrase, summarize, generate, related 
HYPERFORGE_LLM_SMART=chatgpt-4.1 # planner, executor, tool_choice
HYPERFORGE_LLM_FAST=gemini-2.5-flash # sampling, configuration
HYPERFORGE_LLM_REASONING=chatgpt-o3-mini # decision, conditional, external

Backwards Compatibility

  • "chatgpt-4.1" (legacy JSON) → auto-coerced to LLMConfig(model_id="chatgpt-4.1")
  • Old configs load without error; re-saved in structured format
  • _type: "llm_config" discriminator enables future Alembic model rename migrations

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Introduces a structured LLMConfig model to replace plain string model identifiers in agent configurations, enabling centralized environment-configurable defaults and optional reasoning configuration while keeping legacy stored configs loadable via coercion.

Changes:

  • Added hyperforge.llm_config (LLMConfig, LLMField, defaults, reasoning helpers) and updated many agent config schemas to use LLMField with centralized defaults.
  • Added DB/Alembic-oriented migration helpers to rename model IDs inside nested stored JSONB configs, plus unit/integration tests.
  • Updated manager and several agent runtime call sites to pass the correct model identifier string (.model_id) to external request models.

Reviewed changes

Copilot reviewed 28 out of 29 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
uv.lock Adds hyperforge-restricted as a dependency entry.
hyperforge/tests/unit/arag/test_llm_migration_utils.py Tests JSON-walk replacement and a DB-backed migration path.
hyperforge/tests/unit/arag/test_llm_config.py Tests string→LLMConfig coercion and reasoning resolution behavior.
hyperforge/src/hyperforge/manager.py Accepts `str
hyperforge/src/hyperforge/llm_config.py Defines LLMConfig/LLMField, reasoning config types, and env-driven defaults.
hyperforge/src/hyperforge/db/llm_migration_utils.py Implements JSONB walk/replace + multi-table migration helper for model renames.
hyperforge/src/hyperforge/context/config.py Migrates context agent config model fields from str to LLMField.
hyperforge/src/hyperforge/context/agent.py Updates rephrase API signature to accept ModelParam.
agents/summarize/src/hyperforge_summarize/config.py Converts summarize agent model field to LLMField with defaults.
agents/summarize/src/hyperforge_summarize/agent.py Uses .model_id when building ChatModel.
agents/smart/src/hyperforge_smart/config.py Converts planner/executor model fields to LLMField with defaults.
agents/smart/src/hyperforge_smart/agent.py Uses .model_id when building ChatModel for tool selection.
agents/restricted/src/hyperforge_restricted/config.py Converts decision model to LLMField with reasoning-tier default.
agents/restart/src/hyperforge_restart/config.py Converts model to LLMField and adds field metadata.
agents/rephrase/src/hyperforge_rephrase/config.py Converts rephrase model to LLMField with centralized default.
agents/related/tests/test_related.py Updates tests to construct RelatedAgentConfig with LLMConfig and asserts .model_id.
agents/related/src/hyperforge_related/config.py Converts related agent model to LLMField with default factory.
agents/related/src/hyperforge_related/agent.py Import order change (no functional change).
agents/nucliadb/src/hyperforge_nucliadb/basic_ask_config.py Converts generative_model to LLMField with centralized defaults.
agents/nucliadb/src/hyperforge_nucliadb/basic_ask_agent.py Uses .model_id for AskRequest.generative_model.
agents/nucliadb/src/hyperforge_nucliadb/ask/config.py Converts configuration_model to LLMField with fast-tier default.
agents/nucliadb/src/hyperforge_nucliadb/advanced_ask_config.py Converts generative_model to LLMField with centralized default.
agents/nucliadb/src/hyperforge_nucliadb/advanced_ask_agent.py Uses .model_id for AskRequest.generative_model.
agents/mcp/src/hyperforge_mcp/config.py Converts MCP model fields to LLMField with tiered defaults.
agents/mcp/src/hyperforge_mcp/agent.py Uses .model_id for ChatModel / CreateMessageResult model fields.
agents/generate/src/hyperforge_generate/config.py Converts generate agent model to LLMField with centralized default.
agents/generate/src/hyperforge_generate/agent.py Uses .model_id when building ChatModel.
agents/external/src/hyperforge_external/config.py Converts external-call agent model to LLMField with reasoning-tier default.
agents/conditional/src/hyperforge_conditional/conditional.py Converts conditional agent model to LLMField with reasoning-tier default.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread hyperforge/src/hyperforge/db/llm_migration_utils.py Outdated
Comment thread hyperforge/src/hyperforge/db/llm_migration_utils.py
@carlesonielfa carlesonielfa marked this pull request as ready for review July 7, 2026 14:42
@carlesonielfa carlesonielfa requested a review from a team July 7, 2026 14:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants